package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserAuthVo;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName UserController
 * @Description: 类描述
 * @Author: admin
 * @CreateDate: 2024/7/22 17:33
 * @UpdateUser: 更新人
 * @UpdateDate: 2024/7/22 17:33
 * @UpdateRemark: 更新的信息
 * @Version: 1.0
 */


@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户列表
     * @param page
     * @param limit
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result userList(@PathVariable("page") Long page,
                           @PathVariable("limit") Long limit,
                           UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageResult =userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(pageResult);
    }

    /**
     * 锁定用户
     * @param userId 用户id
     * @param status 0：锁定 1：正常
     * @return
     */
    @GetMapping("lock/{userId}/{status}")
    public Result lockUser(@PathVariable("userId") Long userId,
                           @PathVariable("status") Integer status) {
        userInfoService.lockUser(userId, status);
        return Result.ok();
    }

    /**
     * 用户详情
     * @param userId
     * @return
     */
    @GetMapping("show/{userId}")
    public Result showUser(@PathVariable("userId") Long userId) {
        Map<String,Object> map =userInfoService.show(userId);
        return Result.ok(map);
    }

    /**
     * 认证审批
     * @param userId
     * @param authStatus
     * @return
     */
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable("userId") Long userId,
                              @PathVariable("authStatus") Integer authStatus) {
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }
}
